class ElckerStorageUtils {
    setValToStorage = (key: any, value: any) => {
        if (!window.localStorage) {
            console.log("浏览器支持localstorage");
        } else {
            localStorage.setItem(
                key,
                JSON.stringify({
                    valueObj: value,
                    adTime: new Date().getTime(),
                })
            );
        }
    }
    readValueFormStorage = (key: any, chtime: any) => {
        if (!window.localStorage) {
            console.log("浏览器支持localstorage");
            return null;
        } else {
            const obj = JSON.parse(window.localStorage.getItem(key) + "");
            if (obj) {
                if (chtime == true) {
                    if (new Date().getTime() - obj.adTime > 259200000) {
                        localStorage.removeItem(key)
                        console.log("数据已过期");
                        return null;
                    }
                }
                return obj.valueObj
            } else {
                return null;
            }
        }
    }
}

export const ElckerStorage = new ElckerStorageUtils()